#ifndef INTERFACE_TEXTBOX_HPP
#define INTERFACE_TEXTBOX_HPP

#include "Widget.hpp"

namespace mi
{
    class Textbox : public Widget
    {
    public:
        Textbox (std::string text);

        // Textbox specific functions

        bool OneLine ();

        bool OneLine (bool setTo);

        bool Editable ();

        bool Editable (bool setTo);

        // Overwrite input functions

        Widget* MouseClick(sf::Mouse::Button button, sf::MouseState state, int x, int y);
        
        Widget* MouseDragged(int x, int y, int dx, int dy);

        Widget* MouseWheel(int dir);
        
        Widget* KeysDown(sf::Event::KeyEvent key);
        
        Widget* KeysUp(sf::Event::KeyEvent key);

        Widget* TextEntered(char ch);

        //  Overwrite the draw and update

        void Draw2D ();    

        bool Update (double dTime);

    protected:
        void OnSizeChange(Vec2i oldSize);

        void OnPositionChange(Vec2i oldPosition);

        void OnTextChanged();

        void DrawScrollBar();

    private:

        struct textline
        {
            std::string text;
            Vec2i pos;
        };

        // general flags
        
        bool oneLine;

        bool active;

        bool editable;

        // scroll related vars

        int scrollOffset;

        int tmpScroll;

        int scrollPos;

        bool dragScroll;

        int scrollMult; // bigger = faster scrolling

        // scroll bar
        int scrollbarStart;

        int scrollbarEnd;

        bool drawScrollbar;
        
        // text-display vars
        
        int textHeight;
        
        int lineHeight;
        
        int lineSpacing;
        
        int padding;
        
        int startingLine, endingLine;
        
        int scrollbarWidth;
        
        std::deque<sf::Text> textLines;
        
        std::deque<std::string> dividedLines;
        
        // Functions

        void RestructureText();

        std::deque<std::string> GetDividedLines ();

        void SetTextLines ();

        void ScrollToBottom ();

        bool ScrollBy(int amount);

        //sf::Text textLines;
    };
}

#endif